package com.zsd.android.rxjavalib;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class SubscribeOn<T> implements ObservableOnSubscribe<T> {

    private final ExecutorService executorService;
    private ObservableOnSubscribe<T> source;

    public SubscribeOn(ObservableOnSubscribe<T> source) {
        this.source = source;
        executorService = Executors.newCachedThreadPool();
    }

    @Override
    public void subscribe(final Observer<? super T> observableEmitter) {
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                source.subscribe(observableEmitter);
            }
        });
    }
}
